package com.ff.javamonkey.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;

import com.ff.javamonkey.socket.message.Message;
import com.ff.javamonkey.xmodem.XModem;

public class XSocketConnect implements ClientConnect {
	// Debugging
	private static final String TAG = "XSocket";
	// General variables
	private boolean connected = false;
	// Socket variable
	private Socket sock;
	
	public XSocketConnect() {
		sock = new Socket();
	}
	
	public void connect(String host, String pass) throws IOException {
		InetSocketAddress inetSock = new InetSocketAddress("10.0.2.2", 9000);
		sock.connect(inetSock);
		setConnected(true);
	}

	public void close() throws IOException {
		// TODO Auto-generated method stub

	}

	public int getFileSize(String fileName) throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	public byte[] getFile(String fileName) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	public File getFile(String fileName, String fileOut) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	public String[] getFileNames(String directory, String extension) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isConnected() {
		return connected;
	}

	public int getConnectionStatus() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setConnectionStatus(int stat) {
		// TODO Auto-generated method stub

	}

	public int getReadStatus() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setReadStatus(int stat) {
		// TODO Auto-generated method stub

	}

	public void write(Message message) {
		// TODO Auto-generated method stub

	}

	public String read() {
		// TODO Auto-generated method stub
		return null;
	}

	public void connect(String host, int port) throws IOException {
		// TODO Auto-generated method stub
		
	}
	
	public void setConnected(boolean connected) {
		this.connected = connected;
	}

	public void write(File file) {
		// TODO Auto-generated method stub
		XModem xmodem;
		try {
			xmodem = new XModem(
					new DataInputStream(sock.getInputStream()), 
					new DataOutputStream(sock.getOutputStream()), 
					new PrintWriter(System.err));
			xmodem.send(file.getAbsolutePath());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
